"""
@author: Sergiy Tsymbalyuk
"""

from datetime import date, timedelta

from pylons import request
from webhelpers.html.builder import HTML, literal

from chowa.lib.base import render, Session
from chowa.model.site import BlogPost

class Blog(object):
    def __init__(self, options={}):
        self.options = options
    
    def render(self):
        blog_id = self.options.get('id')
        query = Session.query(BlogPost).order_by('created desc')
        title = text = '--'
        if query.count():
            post = query.first()
            title = post.title
            text = post.text
        return HTML.tag('h3', title, style='margin:8px') \
             + HTML.tag('p', literal(text.replace('\n', '<br/>')),
                        style='margin:8px',
                        class_='blog-post')
